//  This file is part of Swordbible - http://www.swordwarrior.net
//  Copyright (C) 2003-2009 Manu Mital mital.manu@gmail.com

//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2, or (at your option)
//  any later version.

//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.

//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#pragma once

#include "SwordBibleFonts.h"
#include "AutoRichEditCtrl.h"
#include "ColorMgr.h"
#include "afxcmn.h"
#include "afxdtctl.h"
#include "MyToolBar.h"
#include "SwordbibleDoc.h"
#include "afxwin.h"
#include "CustomRs.h"
#include "TransparentImage.h"
#include "TextProgressCtrl.h"
#include "RangeSet.h"
#include <afxpriv.h>

// CDailyBiblePage dialog

class CDailyBiblePage : public CPropertyPage
{
	DECLARE_DYNAMIC(CDailyBiblePage)

public:
	CDailyBiblePage();
	sword::SWModule* pModuleActive;
	virtual ~CDailyBiblePage();

	inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
	CString ReadingDate;
	CString Data;
	CString isRead;
	void Delete();
	void CreateBlankRecord();
	void AddNew();
	void UpdateBoundData();
	void GenerateError(HRESULT hr, PWSTR pwszDescription);
	BOOL CreateDB(); 
	void CreateDatabaseX();
	void RefreshBoundData();
	void ComputePercentComplete();
	void CompactDatabase();
	
	void AddPlanNames();  /* Add the reading plans (database tables) to planNames array */
	void SelectTable(CString tableName); /* Select a different reading plan   */
	BOOL AddTable(CString TableName, CString C1, CString C2, CString C3);    /* Add a new reading plan */
	BOOL DeleteTable(CString TableName); /* Delete a reading plan */
	void SaveReadingData(CString date, CString readStatus, CString readingdata);   /* save the entry to Data.mdb database
																				   or create new if DNE */
	void DeleteReadingData(CString date); /* Delete reading data for a particular date */
    void GetReadingData(CString date); 	/* Queries the database to retrieve a string of verses for given date*/


// Dialog Data
	enum { IDD = IDD_DAILYBIBLEPAGE };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	CMyToolBar m_wndFormatBar;
	DECLARE_MESSAGE_MAP()


public:
	
	virtual BOOL OnInitDialog();
	static CString path;
	void showText();
	void UpdateCalendarDate();
	BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR,   LRESULT *pResult);

	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPrint();
	afx_msg void OnPreviousDate();
	afx_msg void OnNextDate();
	afx_msg void OnSelectAll();
	afx_msg void OnCopy();
	afx_msg void OnSelCalendar(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnShowVersions();
	afx_msg void OnChangeReadingPlans();
	afx_msg void OnZoom();
	afx_msg void OnUpdateZoom(CCmdUI *pCmdUI);
	afx_msg void OnEnMsgfilter(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnAddPlan();
	afx_msg void OnRemovePlan();
	afx_msg void OnFocusRichEditDate();
	afx_msg void OnFocusRichName();
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	CButton readCtrl;
	CTextProgressCtrl DBProgress;
	CAutoRichEditCtrl PlanNameCtrl;
	CMonthCalCtrl DBCalendarCtrl;
	CAutoRichEditCtrl m_rich;
	CTransparentImage CrystalCal;
	CAutoRichEditCtrl m_richeditDate;
	CPoint pt;   // stores top left corner of the calendar image
	static CStringArray planNames;


private:
	int active;
	CString timeKey;
	int month, day, year;
	CString timeFormatted;
	CString plan;	
	int numRead;   // for the reading plans
	int numTotal;   // for the reading plans

	CStringArray Footnotes;
	CStringArray Xrefs;
  CRangeSet XLimits;

	
	CCustomRsDB m_rsRecSet;
	CString m_strCmdText;
	CString m_strConnection;
	IADORecordBinding* m_piAdoRecordBinding;
	_RecordsetPtr m_pRs;
	BOOL IsAppData;
	ADOX::_CatalogPtr m_pCatalog;


private:
		void ZoomText();
		void OnRightButtonDown();
    void OnLeftButtonDown();
		void UpdateProgress();

   void AddHeadings(CString& Text);   // add pre-verse headings to the beginning of each verse
   void AddFootNotes(CString& VerseText, int verse);
	 void AddXref(CString& VerseText, int verse);
   void SetXLimits();
		
		
		afx_msg void OnDestroy();
		afx_msg void OnCheckRead();

};
